using FileManager.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;

namespace FileManager.Models
{
    public static class DbInitializer
    {
        public static void Initialize(AppDbContext context)
        {
            // 确保数据库已创建
            context.Database.EnsureCreated();

            // 如果有迁移未应用，则应用迁移
            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            // 初始化基础数据
            if (!context.Tags.Any())
            {
                context.Tags.AddRange(
                    new Tag { Name = "重要", Color = "#FF5252" },
                    new Tag { Name = "工作", Color = "#4285F4" },
                    new Tag { Name = "个人", Color = "#34A853" }
                );
                context.SaveChanges();
            }
        }
    }
}